﻿using Abp.Application.Services.Dto;
using Abp.Domain.Repositories;
using Abp.Domain.Services;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;

namespace LeadThing.AbpZeroTemplate.VersionApps
{
    /// <summary>
    /// APP版本号业务管理
    /// </summary>
    public class VersionAppManage : IDomainService
    {
        private readonly IRepository<VersionApp, long> _versionAppRepository;

        /// <summary>
        /// 构造方法
        /// </summary>
        public VersionAppManage(IRepository<VersionApp, long> versionAppRepository)
        {
            _versionAppRepository = versionAppRepository;
        }

        //TODO:编写领域业务代码

        /// <summary>
        /// 获取所有APP标记
        /// </summary>
        /// <returns></returns>
        public List<ComboboxItemDto> GetAllVersionFlagList()
        {
            List<ComboboxItemDto> List = new List<ComboboxItemDto>();
            Type t = typeof(FlagEnum);
            Array arrays = Enum.GetValues(t);

            for (int i = 0; i < arrays.LongLength; i++)
            {
                FlagEnum test = (FlagEnum)arrays.GetValue(i);
                FieldInfo fieldInfo = test.GetType().GetField(test.ToString());
                object[] attribArray = fieldInfo.GetCustomAttributes(false);

                ComboboxItemDto model = new ComboboxItemDto()
                {
                    Value = Convert.ToInt32(arrays.GetValue(i)).ToString(),
                    DisplayText = ((DescriptionAttribute)attribArray[0]).Description
                };
                List.Add(model);
            }

            return List;
        }


        /// <summary>
        ///     初始化
        /// </summary>
        private void Init()
        {

        }
    }
}
